$(function(){

});
function exit(){
	$("#auId").val("");
	$("#auditPass").val("");
	$("#auIdea").val("");
	$("#allId").val("");
	load();
	//关闭所有页面层
	layer.closeAll('page');
}
layui.use(['form', 'layedit', 'laydate','table'], function(){
	var table = layui.table
	,laydate = layui.laydate
	,form = layui.form
	,layer = layui.layer
	,layedit = layui.layedit;

	//日期
	laydate.render({
		elem: '#date'
	});

	laydate.render({
		elem: '#time'
	});

	laydate.render({
		elem: '#date2'
	});

	laydate.render({
		elem: '#time2'
	});

	//监听工具条
	table.on('tool(demo)', function(obj){
		var da = obj.data;
		if(obj.event === 'detailPro'){
			layer.open({
				type: 1	 //此处以iframe举例
				,title: '生产详情'
					,area: ['1000px','490px']
			,offset: 'auto'
				,content:$('#detailProDiv')
				,success: function(layero){
					//执行重载
					table.reload('cxDetailTable', {
						page: {
							curr: 1 //重新从第 1 页开始
						}
					,where: {
						proId: da.all_id,
					}
					});
					load();
				},end : function() {
					//弹框关闭的回调函数
					$("#detailProDiv").hide();
				}
			});
		}else if(obj.event === 'detailAudit'){
			layer.open({
				type: 1	 //此处以iframe举例
				,title: '审核详情'
					,area: ['1000px','490px']
			,offset: 'auto'
				,content:$('#detailAuditDiv')
				,success: function(layero){
					//执行重载
					table.reload('auditTable', {
						page: {
							curr: 1 //重新从第 1 页开始
						}
					,where: {
						auId:da.au_id
					}
					});
					load();
				},end : function() {
					//弹框关闭的回调函数
					$("#detailAuditDiv").hide();
				}
			});
		}else if(obj.event === "edit"){
			layer.open({
				type: 1	 //此处以iframe举例
				,title: '审核'
					,area: ['500px','400px']
			,offset: 'auto'
				,content:$('#auditDiv')
				,success: function(layero){
					$("#auId").val(da.au_id);
					$("#allId").val(da.all_id);
					load();
				},end : function() {
					//弹框关闭的回调函数
					$("#auditDiv").hide();
					exit();
				}
			});
		}

	});
	var $ = layui.$, active = {
			reload: function(){
				var date = $('#date');
				var time = $('#time');
				var auState = $('#auStateSelect');
				//执行重载
				table.reload('idTest', {
					page: {
						curr: 1 //重新从第 1 页开始
					}
				,where: {
					date: date.val(),
					time: time.val(),
					auState: auState.val(),
				}
				});
			},
			reloadProDetail:function(){
				var date = $('#date2');
				var time = $('#time2');
				var comName = $('#comName');
				//执行重载
				table.reload('cxDetailTable', {
					page: {
						curr: 1 //重新从第 1 页开始
					}
				,where: {
					date: date.val(),
					time: time.val(),
					comName: comName.val(),
				}
				});
			}
	};

	$('.demoTable .layui-btn').on('click', function(){
		var type = $(this).data('type');
		active[type] ? active[type].call(this) : '';
	});


	$("#tj").on('click', function(){
		findAuIdea();
		var countyz=0;
		$.each($(".shYz"),function(index,item){
			if($(item).val()=="√"){
				countyz++;
			}
		});
		if(countyz==1){
			var index = layer.load(0, {shade: false});
			var url="../../audit/addProAudit.action";
			var data=$("#shForm").serialize();
			$.post(url,data,function(mes){
				layer.close(index);
				if(mes==1){
					layer.msg("审核成功");
					$("#auditDiv").hide();
					exit();

					//执行重载
					table.reload('idTest', {
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				}else{
					layer.msg("审核失败");
				}
			},"json");
		}
	});

	$('.demoTable #insert').on('click', function(){
		layer.open({
			type: 1	 //此处以iframe举例
			,title: '增加类型'
				,area: ['500px', '260px']
		,offset: 'auto'
			,content:$('#addOrUpdate')
			,end : function() {
				$("#operUser").attr({"disabled":false});
				//弹框关闭的回调函数
				$("#addOrUpdate").hide();
				exit();
			}
		});
	});

	$('#sub').on('click', function(){
		var url="../../matype/addOrUpdate.action"; 
		var data=$("#myform").serialize();
		$.post(url,data,function(mes){
			if(mes==1){
				exit();
				$("#addOrUpdate").hide();
				parent.layer.msg('操作成功', {
					icon: 1
				});
				//重载表单
				active['reload'] ? active['reload'].call(this) : '';
			}else{
				parent.layer.msg('操作失败', {
					icon: 2
				});
			}
		},"json");
	});

});
function findAuIdea(){
	layui.use(['form', 'layedit', 'laydate','table'], function(){
		var layer = layui.layer;
		if($("#auIdea").val()=="" || $("#auIdea").val()==null){
			parent.layer.msg('审核内容不能为空', {
				icon: 5,
				anim :6
			});
			$("#auIdeaInput").val("×");
		}else if($("#auIdea").val().length>100){
			parent.layer.msg('审核内容不能超过100', {
				icon: 5,
				anim :6
			});
			$("#auIdeaInput").val("×");
		}else{
			$("#auIdeaInput").val("√");
		}
	})
}
function load() {
	var form = layui.form
	form.render();
}